package com.ruoyi.web.controller.productManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AccessoryManagement;
import com.ruoyi.system.service.IAccessoryManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配品管理 Controller
 *
 * @author ruoyi
 * @date 2025-05-24
 */
@Api(tags="配品管理")
@RestController
@RequestMapping("/system/accessoryManagement")
public class AccessoryManagementController extends BaseController
{
    @Autowired
    private IAccessoryManagementService accessoryManagementService;

    /**
     * 通过条件查询配品管理列表
     */
    @ApiOperation("通过条件查询配品管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String accessoryName, @RequestParam (required = false) String barcode)
    {
        startPage();
        List<AccessoryManagement> list = accessoryManagementService.selectAccessoryManagementListByConditions(accessoryName,barcode);
        return getDataTable(list);
    }

    /**
     * 导出配品管理列表
     */
    @ApiOperation("导出配品管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:export')")
    @Log(title = "配品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String accessoryName, @RequestParam (required = false) String barcode)
    {
        List<AccessoryManagement> list = accessoryManagementService.selectAccessoryManagementListByConditions(accessoryName,barcode);
        ExcelUtil<AccessoryManagement> util = new ExcelUtil<AccessoryManagement>(AccessoryManagement.class);
        util.exportExcel(response, list, "配品管理数据");
    }

    /**
     * 通过id获取配品管理详细信息
     */
    @ApiOperation("通过id获取配品管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accessoryManagementService.selectAccessoryManagementById(id));
    }

    /**
     * 新增配品管理
     */
    @ApiOperation("新增配品管理")
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "配品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccessoryManagement accessoryManagement)
    {
        return toAjax(accessoryManagementService.insertAccessoryManagement(accessoryManagement));
    }

    /**
     * 修改配品管理
     */
    @ApiOperation("修改配品管理")
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "配品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccessoryManagement accessoryManagement)
    {
        return toAjax(accessoryManagementService.updateAccessoryManagement(accessoryManagement));
    }

    /**
     * 通过id批量删除配品管理信息
     */
    @ApiOperation("通过id批量删除配品管理信息")
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "配品管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accessoryManagementService.deleteAccessoryManagementByIds(ids));
    }
}
